#include "bullet.h"

Bullet::Bullet()
{
    QObject();
    m_pixmap = QPixmap("bullet.png");
    m_x = 0.0;
    m_y = 0.0;
    m_angle = 0;
}
Bullet::Bullet(double x, double y, double angle)
{
    QObject();
    m_pixmap = QPixmap("bullet.png");
    m_x = x;
    m_y = y;
    m_angle = angle;
}

void Bullet::draw(QPainter *painter)
{
   // painter->translate(m_x,m_y);
    painter->setPen(Qt::red);
   // painter->setBackground(QPalette::Base);
    painter->drawPixmap(- m_pixmap.width() / 2.0 + m_x, -m_pixmap.height() / 2.0 + m_y, m_pixmap);
    //painter->end();
}

void Bullet::receiptGeoData(double x, double y, double angle)
{
    m_x = x;
    m_y = y;
    m_angle = angle;
    m_x += cos(m_angle);
    m_y += sin(m_angle);
}
bool Bullet::update()
{
    m_x += cos(m_angle)*5;
    m_y += sin(m_angle)*5;
    if (m_x>=510 || m_x<=-10 || m_y>=510 || m_y<=-10)
        return false;
    return true;
}
QPointF Bullet::locate()
{
    return QPointF(m_x,m_y);
}
